package com.peng._05mvcboot02.common.response;

import lombok.Data;

/**
 * @Author peng
 * @Date 2024-04-25 17:22
 */
@Data
public class JsonResult {
    private Integer code;
    private String msg;
    private Object data;

    public JsonResult(){}

    public JsonResult(StatusCode statusCode, String msg){
        this.code = statusCode.getCode();
        this.msg = msg;
    }
    public JsonResult(StatusCode statusCode){
        this.code = statusCode.getCode();
        this.msg = statusCode.getMsg();
    }

    public JsonResult(StatusCode statusCode, String msg, Object data){
        this.code = statusCode.getCode();
        this.msg = msg;
        this.data = data;
    }

    public JsonResult(StatusCode statusCode,Object data){
        this.code = statusCode.getCode();
        this.msg = statusCode.getMsg();
        this.data = data;
    }

    public static JsonResult success(){
        return new JsonResult(StatusCode.SUCCESS);
    }

    public static JsonResult success(String msg){
        return new JsonResult(StatusCode.SUCCESS, msg);
    }

    public static JsonResult success(Object data){
        return new JsonResult(StatusCode.SUCCESS, data);
    }

    public static JsonResult success(String msg, Object data){
        return new JsonResult(StatusCode.SUCCESS, msg, data);
    }

    public static JsonResult error(){
        return new JsonResult(StatusCode.ERROR);
    }
    public static JsonResult error(String msg){
        return new JsonResult(StatusCode.ERROR, msg);
    }

    public static JsonResult error(Object data) {
        return new JsonResult(StatusCode.ERROR, data);
    }
    public static JsonResult error(String msg, Object data){
        return new JsonResult(StatusCode.ERROR, msg, data);
    }
}
